1
|
|
|
import deepEqual from 'deep-equal'; |
2
|
|
|
import { getLastUpdate } from './lastUpdate'; |
3
|
|
|
|
4
|
|
|
export function shouldGridUpdate(nextProps) { |
5
|
|
|
let result = true; |
|
|
|
|
6
|
|
|
|
7
|
|
|
const { reducerKeys, stateKey, store } = this.props; |
8
|
|
|
|
9
|
|
|
const nextUpdate = getLastUpdate(store, stateKey, reducerKeys); |
10
|
|
|
|
11
|
|
|
result = ( |
12
|
|
|
!deepEqual(nextUpdate, this._lastUpdate) |
13
|
|
|
|| !equalProps(nextProps, this._lastProps) |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
this._lastUpdate = nextUpdate; |
17
|
|
|
this._lastProps = nextProps; |
18
|
|
|
|
19
|
|
|
return result; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
export function shouldPagerUpdate(nextProps, nextState) { |
23
|
|
|
|
24
|
|
|
let result = true; |
|
|
|
|
25
|
|
|
|
26
|
|
|
const limitedNextProps = { |
27
|
|
|
gridData: nextProps.gridData, |
28
|
|
|
state: this.state |
29
|
|
|
}; |
30
|
|
|
|
31
|
|
|
const limitedProps = { |
32
|
|
|
gridData: this.props.gridData, |
33
|
|
|
state: nextState |
34
|
|
|
}; |
35
|
|
|
|
36
|
|
|
result = ( |
37
|
|
|
!deepEqual(limitedNextProps, limitedProps) |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
return result; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
export function shouldHeaderUpdate(nextProps, nextState) { |
|
|
|
|
44
|
|
|
// let result = true; |
45
|
|
|
// to do, stop this |
46
|
|
|
return true; |
47
|
|
|
|
48
|
|
|
/* eslint-disable no-unreachable */ |
49
|
|
|
|
50
|
|
|
// const menuState = state => |
51
|
|
|
// state && state.get('header-row'); |
52
|
|
|
|
53
|
|
|
// const limitedNextProps = { |
54
|
|
|
// columns: nextProps.columns, |
55
|
|
|
// menuState: menuState(nextProps.menuState), |
56
|
|
|
// state: nextState |
57
|
|
|
// }; |
58
|
|
|
|
59
|
|
|
// const limitedProps = { |
60
|
|
|
// columns: this.previousColumns, |
61
|
|
|
// menuState: menuState(this.props.menuState), |
62
|
|
|
// state: this.state |
63
|
|
|
// }; |
64
|
|
|
|
65
|
|
|
// result = ( |
66
|
|
|
// !deepEqual(limitedNextProps, limitedProps) |
67
|
|
|
// ); |
68
|
|
|
|
69
|
|
|
// this.previousColumns = this.props.columns.slice(); |
70
|
|
|
|
71
|
|
|
// return result; |
72
|
|
|
|
73
|
|
|
/* eslint-enable no-unreachable */ |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
export function shouldRowUpdate(nextProps) { |
77
|
|
|
let result = true; |
|
|
|
|
78
|
|
|
|
79
|
|
|
// unique key created by setData action/reducer |
80
|
|
|
const key = nextProps.row.get('_key'); |
81
|
|
|
|
82
|
|
|
const isSelected = rows => Boolean(rows && rows.get(key)); |
83
|
|
|
|
84
|
|
|
const isMenuShown = rows => Boolean(rows && rows.get(key)); |
85
|
|
|
|
86
|
|
|
const isEdited = editorState => Boolean( |
87
|
|
|
editorState |
88
|
|
|
&& editorState.get(key) |
89
|
|
|
&& editorState.get(key).values |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
const limitedNextProps = { |
93
|
|
|
columns: slimColumn(nextProps.columns), |
94
|
|
|
isEdited: isEdited(nextProps.editorState), |
95
|
|
|
currentValues: isEdited(nextProps.editorState) |
96
|
|
|
? nextProps.editorState.get(key) |
97
|
|
|
: null, |
98
|
|
|
isMenuShown: isMenuShown(nextProps.menuState), |
99
|
|
|
row: nextProps.row, |
100
|
|
|
index: nextProps.index, |
101
|
|
|
isSelected: isSelected(nextProps.selectedRows), |
102
|
|
|
isDragging: nextProps.isDragging |
103
|
|
|
}; |
104
|
|
|
|
105
|
|
|
const limitedProps = { |
106
|
|
|
columns: this.previousColumns, |
107
|
|
|
isEdited: isEdited(this.props.editorState), |
108
|
|
|
currentValues: isEdited(this.props.editorState) |
109
|
|
|
? this.props.editorState.get(key) |
110
|
|
|
: null, |
111
|
|
|
isMenuShown: isMenuShown(this.props.menuState), |
112
|
|
|
row: this.props.row, |
113
|
|
|
index: this.props.index, |
114
|
|
|
isSelected: isSelected(this.props.selectedRows), |
115
|
|
|
isDragging: this.props.isDragging |
116
|
|
|
}; |
117
|
|
|
|
118
|
|
|
this.previousColumns = slimColumn(this.props.columns.slice()); |
119
|
|
|
|
120
|
|
|
result = ( |
121
|
|
|
!deepEqual(limitedNextProps, limitedProps) |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
return result; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
export const slimColumn = cols => |
128
|
|
|
cols.map(col => ({ hidden: col.hidden, dataIndex: col.dataIndex })); |
129
|
|
|
|
130
|
|
|
export const equalProps = (props = {}, newProps = {}) => { |
131
|
|
|
return props.height === newProps.height |
132
|
|
|
&& deepEqual(props.classNames, newProps.classNames) |
133
|
|
|
&& deepEqual(props.events, newProps.events); |
134
|
|
|
}; |
135
|
|
|
|